package cn.kgc.vue.common;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Author: 课工场
 * @Version: v1.0  2023/8/8
 * @Description:
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ResponseResult {

    private Integer code;
    private String msg;
    private Object data;


    // 响应成功信息没有数据
    public void success(ResponseStatus responseStatus){
        this.code = responseStatus.getCode();
        this.msg = responseStatus.getMsg();
    }

    public void success(){
        this.code = ResponseStatus.SUCCESS.getCode();
        this.msg = ResponseStatus.SUCCESS.getMsg();
    }

    // 响应成功信息有数据
    public void success(ResponseStatus responseStatus,Object data){
        this.code = responseStatus.getCode();
        this.msg = responseStatus.getMsg();
        this.data = data;
    }

    // 响应失败信息
    public void fail(ResponseStatus responseStatus){
        this.code = responseStatus.getCode();
        this.msg = responseStatus.getMsg();
    }

    public void fail(){
        this.code = ResponseStatus.FAIL.getCode();
        this.msg = ResponseStatus.FAIL.getMsg();
    }

}
